﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace Meqs.Entity
{
    [Serializable]
    public class UserSerial
    {
        public UserSerial()
        {
        }

        public UserSerial(byte[] data)
        {
            try
            {
                BinaryFormatter b = new BinaryFormatter();
                UserSerial us = b.Deserialize(new MemoryStream(data)) as UserSerial;
                _UsedNumber = us.UsedNumber;
                _userSecret = us.UserSecret;
                _snum = us.SNum;
            }
            catch {
                throw new Exception("对象实例错误");
            }
        }
        private int _UsedNumber=0;//可用次数
        private object _userSecret;//序列号和机器码的运算结果
        private string _snum;//序列号
        public int UsedNumber
        {
            get { return _UsedNumber; }
            set { _UsedNumber = value; }
        }
        public object UserSecret
        {
            get { return _userSecret; }
            set { _userSecret = value; }
        }
        public string SNum
        {
            get { return _snum; }
            set { _snum = value; }
        }
        public byte[] GetArray()
        {
            BinaryFormatter b = new BinaryFormatter();
            MemoryStream ss = new MemoryStream();
            b.Serialize(ss, this);
            byte[] buffer = ss.ToArray();
            return buffer;
        }
    }
}
